package com.jianyun.jyzs.model;

import com.jianyun.jyzs.bean.SignResult;
import com.jianyun.jyzs.http.Api;
import com.jianyun.jyzs.http.CustomCallback;
import com.jianyun.jyzs.http.RetrofitHelper;
import com.jianyun.jyzs.model.imdoel.ISignModel;

import java.util.HashMap;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by yangshijun on 2018/5/30.
 */

public class SignModel implements ISignModel {

    private static SignModel model;

    private SignModel(){}

    public static SignModel getInstance(){
        if (model==null){
            model=new SignModel();
        }
        return model;
    }

    @Override
    public void startSign(HashMap<String, String> map, final OnSignListener onSignListener) {
        Api api = RetrofitHelper.builderErpRoot().create(Api.class);
        api.userSignDao(map)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new CustomCallback<SignResult>() {
                    @Override
                    protected void onResponse(SignResult response) {

                        if (response.isResult()){
                            onSignListener.onSuccess(response);
                        }else {
                            onSignListener.onFailed(response.getMessage());
                        }
                    }

                    @Override
                    protected void onException(String msg) {
                        onSignListener.onFailed(msg);
                    }
                });
    }
}
